package com.deepconv.abbebot.xread.application;

import android.app.Application;
import android.content.Intent;

import com.deepconv.abbebot.xread.service.XCameraService;
import com.lzy.okgo.OkGo;

import org.litepal.LitePal;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


public class XApplication extends Application {

    private Intent cameraService;

    public static final ScheduledExecutorService scheduler =
            Executors.newScheduledThreadPool(9);

    @Override
    public void onCreate() {
        super.onCreate();

        OkGo.getInstance().init(this);
        /**
         * 初始化数据库
         * */
        LitePal.initialize(this);

        startCameraService();
        scheduler.schedule(new PictureBookAPP(this.getApplicationContext()), 2, TimeUnit.SECONDS);
    }

    private void startCameraService() {
        if (cameraService != null) {
            stopService(cameraService);
            cameraService = null;
        }
        cameraService = new Intent();
        cameraService.setClass(getApplicationContext(), XCameraService.class);
        //cameraService.putExtra(AbbeGameUtil.EXTRA_ABBE_GAME_TYPE, type);
        startService(cameraService);
    }

}
